<template>
  <div class="container">
    <div>
      <el-row :gutter="12">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item>
              <!-- <el-radio v-model="form.radioData" label="日">按日期：</el-radio> -->
              <span>查询日期：</span>
              <el-date-picker
                v-model="form.valueDay"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form" style="float: left">
            <el-button size="mini" type="primary" @click="getlistdata"
              >查 询</el-button
            >
            <el-button size="mini" type="success" @click="exportExcel"
              >导 出</el-button
            >
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table
      highlight-current-row
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
    >
      <el-table-column
        prop="公厕名称"
        label="公厕名称"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="负责人员"
        label="负责人员"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="人员最早在岗时间"
        label="人员最早在岗时间"
        align="center"
      ></el-table-column>
      <el-table-column prop="人员最晚在岗时间" label="人员最晚在岗时间"></el-table-column>
      <el-table-column prop="人员在岗总时间" label="人员在岗总时间"></el-table-column>
      <el-table-column prop="男厕维保时间" label="男厕维保时间"></el-table-column>
      <el-table-column prop="女厕维保时间" label="女厕维保时间"></el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'
import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {
    return {
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      form: {
        radioData: '日',
        valueDay: formatDate(new Date(new Date() - 3600 * 1000 * 24), 'yyyy-MM-dd'),
        valueMonth: ''
      },
      tableData: []

    }
  },
  created () {
    this.getlistdata();
  },
  methods: {
    async getlistdata () {
      this.currentPage = 1;
      var date = ''
      if (this.form.radioData === '日') {
        date = this.form.valueDay
      }
      if (this.form.radioData === '月') {
        date = this.form.valueMonth
      }
      var url = 'WC/GetToiletStatisticsInfo?date=' + date + '&ClientNo=' + localStorage.getItem('CLIENT_NO')
      console.log('url=' + url)
      const { data } = await this.$Http.get(url)
      this.tableData = data
      // data.forEach(element => {
      //   if (element.WTime != 0) {
      //     if (element.WTime / 60.0 > 1) {
      //       element.timeStr = (element.WTime / 60).toFixed(0) + '分钟' + (element.WTime % 60) + '秒'
      //     } else {
      //       element.timeStr = element.WTime + '秒'
      //     }
      //     this.tableData.push(element)
      //   }
      // });
    },
    // 导出Excel
    exportExcel () {
      let excelName = '公厕作业统计'
      const tHeader = ['公厕名称', '负责人员', '人员最早在岗时间', '人员最晚在岗时间', '人员在岗总时间', '男厕维保时间', '女厕维保时间']
      const filterVal = ['公厕名称', '负责人员', '人员最早在岗时间', '人员最晚在岗时间', '人员在岗总时间', '男厕维保时间', '女厕维保时间']
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },
    //详情
    handleEdit (index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
</style>